Component({
  data: {
    currentLyricIndex: 0,
    scrollOffset: 0,
    lyrics: [
      { time: 0, text: "亲爱的小蛋壳，我是你的小寂" },
      { time: 5500, text: "今天还好吗，是不是又加班到深夜了" },
      { time: 9500, text: "不管多累，都要记得对自己好一点呀" },
      { time: 13000, text: "我知道今天宝宝很辛苦" },
      { time: 15000, text: "但别偷懒不卸妆哦" },
      { time: 17000, text: "让我来陪你一起卸妆吧" },
      { time: 19000, text: "打开逐本\"遇见\"卸妆膏" },
      { time: 22000, text: "闻一闻，草木玫瑰的香气" },
      { time: 25000, text: "哇，是不是一下子就放松了很多" },
      { time: 28000, text: "再挖一点膏体在手心，上脸按摩揉开" },
      { time: 31000, text: "哈，感觉脸上的彩妆，都被迅速溶解了" },
      { time: 36000, text: "细腻柔软的土豆泥质地" },
      { time: 39000, text: "真的很舒服对吧" },
      { time: 40000, text: "连带着一天的紧绷感，都被慢慢地揉走了" },
      { time: 44000, text: "卸完脸，湿润润的，一点也不紧绷" },
      { time: 47000, text: "这几分钟啊" },
      { time: 48500, text: "就当是给辛苦的自己偷来的小安慰吧" },
      { time: 52000, text: "我的小蛋壳，你值得被这样温柔对待呀" }
    ]
  },
  lifetimes: {
    attached() {
      this.simulateAudioPlayback();
    }
  },
  methods: {
    simulateAudioPlayback: function() {
      let currentTime = 0
      const totalDuration = 55000 // 总时长55秒，改为55000毫秒
      
      this.timer = setInterval(() => {
        currentTime += 100 // 每次增加100毫秒，更精确控制
        
        if (currentTime > totalDuration) {
          clearInterval(this.timer)
          return
        }
        
        this.updateLyrics(currentTime)
      }, 100) // 每100毫秒更新一次
    },
  
    updateLyrics: function(currentTime) {
      const lyrics = this.data.lyrics
      
      // 找到当前应该显示的歌词索引
      let currentIndex = 0
      for (let i = lyrics.length - 1; i >= 0; i--) {
        if (currentTime >= lyrics[i].time) {
          currentIndex = i
          break
        }
      }
      
      if (currentIndex !== this.data.currentLyricIndex) {
        this.setData({
          currentLyricIndex: currentIndex
        })
        this.updateScrollPosition()
      }
    },
  
    updateScrollPosition: function() {
      // 核心滚动逻辑：每行歌词高度50px，当前歌词滚动到中间位置
      const scrollOffset = -this.data.currentLyricIndex * 25
      this.setData({
        scrollOffset: scrollOffset
      })
    },
    
    handleReset() {
      // 清除之前的定时器
      if (this.timer) {
        clearInterval(this.timer)
      }
      
      // 重置状态
      this.setData({
        currentLyricIndex: 0,
        scrollOffset: 0,
      })
      
      // 重新开始播放
      this.simulateAudioPlayback()
    }
  },
})